package com.cnciems.shardingsphere.crouse.controller;

/**
* @program: study
* @package: com.cnciems.shardingsphere.controller
* @description: TODO
* @author: Haijiang Hu
* @dep R&D SP Co.,Ltd
* @create: 2020-08-18 15:08
* @version V1.0
**/

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cnciems.shardingsphere.crouse.entity.Course;
import com.cnciems.shardingsphere.crouse.mapper.CourseMapper;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
public class CourseController {

    private CourseMapper courseMapper;

    @GetMapping("/insert")
    @Transactional
    public int insert(){
        Course c = new Course();
        int index = 0;
//        for(int i=0;i<20;i++){
            c.setCid(20);
            c.setCname("a");
            c.setUserId(1);
            c.setCstatus("1");
            courseMapper.insert(c);
            index++;
//        }
        return index;
    }

    @GetMapping("/update")
    public int update(){
        Course c = new Course();
        c.setCid(3);
        c.setCname("c");
        c.setUserId(1);
        c.setCstatus("1");
        return courseMapper.updateById(c);
    }
    @GetMapping("/select")
    public List<Course> select(){
        QueryWrapper<Course> c = new QueryWrapper<>();
        c.orderByDesc("cid");
        return courseMapper.selectList(c);
    }
    @GetMapping("/delete/{id}")
    public int delete(@PathVariable("id")int id){
        return courseMapper.deleteById(id);
    }

}
